﻿<UserControl x:Class="Noc.Pomodoro.Controls.TaskGridControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:localControls="clr-namespace:Noc.Pomodoro.Controls"
             mc:Ignorable="d"
             d:DesignHeight="120" d:DesignWidth="240"
             x:Name="ControlRoot">

  <UserControl.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="../Styles/ApplicationStyles.xaml" />
      </ResourceDictionary.MergedDictionaries>

      <BooleanToVisibilityConverter x:Key="BoolToVisibilityConv" />

    </ResourceDictionary>
  </UserControl.Resources>

  <Grid>
    <DataGrid x:Name="gridToday"
              AutoGenerateColumns="False"
              CanUserDeleteRows="False"
              CanUserAddRows="{Binding IsToday, ElementName=ControlRoot}"
              ItemsSource="{Binding Tasks, ElementName=ControlRoot}"
              InitializingNewItem="OnInitializingNewItem">
      <DataGrid.Columns>

        <!-- Task State -->
        <DataGridTemplateColumn Width="20">
          <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
              <Image Style="{StaticResource TaskIconStyle}" MouseLeftButtonUp="OnSwitchTaskStateClicked" />
            </DataTemplate>
          </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

        <!-- Pomodoro List -->
        <DataGridTemplateColumn Header="Pomodoros">
          <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
              <StackPanel Orientation="Horizontal">
                <ItemsControl ItemsSource="{Binding Pomodoros}">
                  <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                      <StackPanel Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                  </ItemsControl.ItemsPanel>
                  <ItemsControl.ItemTemplate>
                    <DataTemplate>
                      <localControls:PomodoroStatusControl Delete="OnPomodoroDelete" />
                    </DataTemplate>
                  </ItemsControl.ItemTemplate>
                </ItemsControl>

                <Image Style="{StaticResource AddPomodoroIconStyle}" MouseUp="OnAddPomodoroIconClicked" />

              </StackPanel>
            </DataTemplate>
          </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

        <!-- Title -->
        <DataGridTextColumn Header="Activity"
                            Width="*"
                            Binding="{Binding Title, Mode=TwoWay}"
                            ElementStyle="{StaticResource TaskTextStyle}" />

        <!-- Control Panel -->
        <DataGridTemplateColumn Header="Actions" Width="64" CanUserResize="False">
          <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>

              <localControls:TaskToolbarControl Task="{Binding}" TaskOperation="OnTaskToolbarOperation" IsEnabled="{Binding CanRun}">
                <localControls:TaskToolbarControl.Style>
                  <Style TargetType="localControls:TaskToolbarControl">
                    <Setter Property="Visibility" Value="Visible" />
                    <Style.Triggers>
                      <DataTrigger Binding="{Binding Title}" Value="{x:Null}">
                        <Setter Property="Visibility" Value="Collapsed" />
                      </DataTrigger>
                      <DataTrigger Binding="{Binding IsToday, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UserControl}}" Value="False">
                        <Setter Property="Visibility" Value="Collapsed" />
                      </DataTrigger>
                    </Style.Triggers>
                  </Style>
                </localControls:TaskToolbarControl.Style>
              </localControls:TaskToolbarControl>

            </DataTemplate>
          </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>

      </DataGrid.Columns>
    </DataGrid>

  </Grid>
</UserControl>